﻿using Authorization.Center.Controllers;
using Authorization.Center.SqlServer;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using S.Parturition.API.Application.Command;

namespace S.Parturition.API.Controllers
{
    /// <summary>
    /// 种母分娩写
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ParturitionController : BaseController
    {

        private readonly IMediator mediator;

        public ParturitionController(IMediator _mediator, MySqlDbContext db) : base(db)
        {
            mediator = _mediator;
        }

        /// <summary>
        /// 添加种母分娩信息
        /// </summary>
        /// <param name="comm"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> AddParturition(AddParturitionCommand comm)
        {
            comm.addParturitionDto.CreateBy = UserStrategyDto.UserTrueName;
            return Ok(await mediator.Send(comm));
        }

        /// <summary>
        /// 修改种母分娩信息
        /// </summary>
        /// <param name="comm"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> UpdateParturitionModel(ParturitionUpdateCommand comm)
        {
            comm.UpdateBy = UserStrategyDto.UserTrueName;
            return Ok(await mediator.Send(comm));
        }


        /// <summary>
        /// 删除种母分娩信息
        /// </summary>
        /// <param name="Ids"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> DeleteParturition(string Ids)
        {
            return Ok(await mediator.Send(new DeleteParturitionCommand() { ParturitionIds = Ids }));
        }

        /// <summary>
        /// 修改种母分娩耳号状态
        /// </summary>
        /// <param name="earTag"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> UpdateParturition(string earTag)
        {
            return Ok(await mediator.Send(new UpdateParturitionCommand() { EarTag = earTag }));
        }

        /// <summary>
        /// 添加羔羊登记
        /// </summary>
        /// <param name="comm"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> AddLambRegistration(AddLambRegistrationCommand comm)
        {
            comm.CreateBy = UserStrategyDto.UserTrueName;
            return Ok(await mediator.Send(comm));
        }

        /// <summary>
        /// 修改羔羊登记
        /// </summary>
        /// <param name="comm"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> UpdateLamb(UpdateLambRegistrationCommand comm)
        {
            comm.UpdateBy = UserStrategyDto.UserTrueName;
            return Ok(await mediator.Send(comm));
        }

        /// <summary>
        /// 删除羔羊登记
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> DeleteLamb(int id)
        {
            return Ok(await mediator.Send(new DeleteLambCommand() { LambRegistrationId = id }));
        }

        /// <summary>
        /// 修改羔羊耳号状态
        /// </summary>
        /// <param name="earTag"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> UpdateLambState(string earTag)
        {
            return Ok(await mediator.Send(new UpdateLambStateCommand() { EarTag = earTag }));
        }

        /// <summary>
        /// 批量修改羔羊耳号状态
        /// </summary>
        /// <param name="comm"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> UpdateLambStateAll(UpdateLambStateAllCommand comm)
        {
            return Ok(await mediator.Send(comm));
        }


    }
}
